#ifndef E4_H
#define E4_H

#include <QFrame>
#include <QThread>
#include "T2C/QueryMicroMan.h"
#include <QCloseEvent>
#include <QDateTimeEdit>
#include <QPushButton>
#include <QGridLayout>
#include <QLabel>
#include <time.h>
#include <QListView>
#include "TChart.h"
#include "Chart.h"

class E4 : public QFrame
{
    Q_OBJECT

    QThread       * thread;
    QueryMicroMan * qmm;
    QString         host;
    int             port;

    QStringList resp;
    QStringList idf;
    QStringList queryList;
    int queryNum;

    QMap< int, QVector< double > > idfDataMap; // [ IDF, vector ]
    QMap< int, QVector< double > > timeDataMap; // [ IDF, vector ]

    QGridLayout   * glay;
    QDateTimeEdit * dteBegin;
    QDateTimeEdit * dteEnd;
    QPushButton   * btnRaedCsArchive;
    QPushButton   * btnConnect;
    QPushButton   * btnDisconnect;
    QPushButton   * btnShowAll3D;
    QLabel        * lblFrom;
    QLabel        * lblTill;
    QListView     * lwPrarmList;

    TChart * chart;

    QList< Chart* > chartList;

    enum QueryType
    {
        qtIDF,
        qtPARAM

    } qType;

    //QVector< double > ndIDs;

public:
    explicit E4( QString h, int p, QWidget * parent = 0 );
    virtual ~E4()
    {
        while( chartList.count() )
        {
            Chart * c = chartList.at( 0 );
            chartList.removeOne( c );
            delete c;
        }
        delete qmm;
        delete thread;
        delete chart;
    }

    //void SetupNodeIDs( QVector< double > d ) { ndIDs = d; }

private:
    void handleIdfList( QString & s );
    void handleDataList( QString & s );
    void startIdfQueries();
    void enableControls( bool e = true );
    time_t convertTime( QString s );
    void enableChartStarters();
    void fillParamList();

protected:
    E4(){}

signals:

public slots:

private slots:
    void sltReceive( QString s );
    void sltReceive();
    void sltConnected();
    void sltDisconnected();
    void sltReadCsArchive();
    void sltConnect();
    void sltDisconnect();
    void sltParamListDblClick( QModelIndex ind );
    void sltShowAll3D();

};

#endif // E4_H
